package com.ms.demo;

import com.ms.demo.entity.Emp;
import com.ms.demo.mapper.EmpDataMapper;
import com.ms.demo.utils.SqlSessionUtils;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

/**
 * @description: 单一操作MySQL
 * @author: ms
 * @create: 2022-08-20 17:23
 */
public class MybatisMysqlTest1 {

    @Test
    public void insertEmpDataTest(){
        SqlSession session = SqlSessionUtils.getSqlSession();
        EmpDataMapper mapper = session.getMapper(EmpDataMapper.class);
        Emp emp = new Emp(null,"小明",23,"男","在职1",null,null);
        mapper.addNewEmpOne(emp);
        System.out.println(emp.getId());
    }

    @Test
    public void deleteEmpDataTest(){
        SqlSession session = SqlSessionUtils.getSqlSession();
        EmpDataMapper mapper = session.getMapper(EmpDataMapper.class);
        mapper.deleteOneEmp("8");
    }

    @Test
    public void updateEmpDataTest(){
        SqlSession session = SqlSessionUtils.getSqlSession();
        EmpDataMapper mapper = session.getMapper(EmpDataMapper.class);
        Emp emp = new Emp(7,"小明2",23,"男","在职2",null,null);
        mapper.updateEmpInfo(emp);
        System.out.println(emp.getId());
    }


    @Test
    public void selectEmpDataTest(){
        SqlSession session = SqlSessionUtils.getSqlSession();
        EmpDataMapper mapper = session.getMapper(EmpDataMapper.class);
        Emp emp = mapper.selectEmpOneById(7);
        System.out.println(emp);
    }

}
